<?php
/**
 * Created by PhpStorm.
 * User: yangyulu
 * Date: 2020/3/1
 * Time: 下午7:53
 */
class Admin_experienceController extends Controller{
    public function listAction(){
        $page = Request::getParams('page', 1);
        $pageSize = Request::getParams('pageSize', 20);

        $categoryId = Request::getParams('categoryId');
        $where = $value = $url = array();
        if ($categoryId) {
            $where[] = 'project_id =?';
            $value[] = $categoryId ;
            $url['categoryId'] = $categoryId;
        }
        $where[]="type=?";
        $value[]=1;
        $total = self::model('project_comment')->count(null, $where, $value);
        $list = self::model('project_comment')->limit(($page - 1) * $pageSize, $pageSize)->order('id desc')->getAll($where, $value);
        $this->assign(array(
            'page' => $page,
            'pageSize' => $pageSize,
            'total' => $total,
            'list' => $list,
            'categoryId' => $categoryId,
            'categoryList' => self::model('project_list')->getAll(),
            'pageHtml' => self::instance('Pagination')->page($page)->num($pageSize)->total($total)->url(Router::getBaseUrl() . '/admin_experience/list?' . ($url ? http_build_query($url) : '') . '&page=')->rendHtml(),
        ));
        $this->display();
    }

    public function detailsAction(){
        $experienceId=Request::getParams("experienceId");
        if (Request::isGet()) {
            $experienceId = Request::getParams('experienceId');
            $info = self::model("project_comment")->getOne("id=?", $experienceId);

            $this->assign([
                "details" => $info,
            ]);
            $this->display();
            exit();
        }
        $res=self::model('project_comment')->update(["status"=>1],"id=?",$experienceId);
        if($res){
            Response::ajax(200, "审核成功");
        }else{
            Response::showMsg('审核失败');
        }
    }

    public function applyAction(){
        $experienceId=Request::getParams('experienceId');
       $info= self::model('project_comment')->getOne(["id=?","status=?"],[$experienceId,0]);
       if(empty($info)){
           Response::showMsg('信息不存在，无法前台显示');
       }
       $res=self::model('project_comment')->update(["status"=>1],"id=?",$experienceId);
       if($res){
           self::model('project_comment')->medal($info["user_id"]);
           Response::ajax(200, "前台显示成功");
       }else{
           Response::showMsg('前台显示失败');
       }

    }

    public function webApplyAction(){
        $experienceId=Request::getParams('experienceId');
        $info= self::model('project_comment')->getOne(["id=?","is_recommend=?"],[$experienceId,0]);
        if(empty($info)){
            Response::showMsg('信息不存在，无法前台显示');
        }
        $res=self::model('project_comment')->update(["is_recommend"=>1],"id=?",$experienceId);
        if($res){
            Response::ajax(200, "首页展示成功");
        }else{
            Response::showMsg('首页展示失败');
        }

    }

    public function deleteAction(){
        $experienceId=Request::getParams('experienceId');
        $info= self::model('project_comment')->getOne(["id=?","status=?"],[$experienceId,1]);
        if(empty($info)){
            Response::showMsg('信息不存在，无法前台显示');
        }
        $res=self::model('project_comment')->update(["status"=>0],"id=?",$experienceId);
        if($res){
            Response::ajax(200, "屏蔽成功");
        }else{
            Response::showMsg('屏蔽失败');
        }
    }
}